package cn.wx.controller;

import cn.wx.domain.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/order/{id}")
    @HystrixCommand(fallbackMethod = "goUserFallback")
    public User goUser(@PathVariable Long id) {
       //String URl = "http://localhost:10020/user/"+id;

        String URl = "http://user-server:10020/user/"+id;
        //发送请求
        User forObject = restTemplate.getForObject(URl, User.class);
        return forObject;
    }
    //调用失败后执行这个方法，方法名和返回值，参数与上面的一致

    public User goUserFallback(@PathVariable Long id ){
        return new User(id,"王天霸","启动断熔");
    }



}